﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sekretar.DataLayer;

namespace Sekretar.Repository
{
    public class RStrucnaSprema : BaseRepository, InterfaceRepository<StrucnaSprema>
    {
        public IQueryable<StrucnaSprema> VratiSve()
        {
            dc = new SekretarDataContext();
            return dc.StrucnaSpremas;
        }

        public StrucnaSprema Nov()
        {
            this.jeNov = true;

            StrucnaSprema n = new StrucnaSprema();
            n.Status = true;
            n.KorisnikId = Common.Properties.Settings.Default.KorisnikId;
            n.DatumRada = Common.Tools.SqlFunkcije.VratiTrenutnoVreme();

            return n;
        }

        public StrucnaSprema Izmeni(int id)
        {
            return dc.StrucnaSpremas.SingleOrDefault(c => c.StrucnaSpremaId == id);
        }

        public int Snimi(StrucnaSprema t)
        {
            if (this.jeNov) dc.StrucnaSpremas.InsertOnSubmit(t);
            dc.SubmitChanges();
            return t.StrucnaSpremaId;
        }

        public void Brisi(int id)
        {
            dc.StrucnaSpremas.DeleteOnSubmit(dc.StrucnaSpremas.SingleOrDefault(c => c.StrucnaSpremaId == id));
            dc.SubmitChanges();
        }
    }
}
